home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Games / NeXTmj / Source / GameCoordinator.h < prev    next >
C/C++ Source or Header  |  1991-03-22  |  6KB  |  189 lines

  1.  
  2. /*
  3.  * This object is the heart of the game.
  4.  *    Many of the standard GUI interface calls pass 
  5.  *    through a translation object and forwarded to this object.
  6.  *
  7.  * This is a rather large object.  It has to coordinate many
  8.  *    functions.
  9.  *
  10.  $Author$
  11.  $Header$
  12.  *
  13.  $Log$
  14.  */
  15.  
  16. #import    "BoardScramble.h"
  17. #import    "GameTileArray.h"
  18. #import    "Help.h"
  19. #import    "IntegerList.h"
  20. #import    "TileCountManager.h"
  21. #import    "TileDescriptionArray.h"
  22.  
  23.  
  24. extern "Objective-C" {
  25. #import    <appkit/appkit.h>
  26.  
  27. #import    "GameBoardView.h"
  28. }
  29.  
  30.  
  31. class GameCoordinator {
  32. private:
  33.                                                 // This flag is used by the updateView()
  34.                                                 //    method.  It is cleared at the begining 
  35.                                                 //    of a constructor and set as the constructor's
  36.                                                 //    last statement.
  37.                                                 // This flag prevents the updateView() from
  38.                                                 //    forcing the display of the tiles.  During
  39.                                                 //    dearchiving of the code the constructor
  40.                                                 //    proves to be a bad place for the
  41.                                                 //    -display method to be sent to the Game
  42.                                                 //    Board view.
  43.     BOOL                    initialized;
  44.                                                 // This is the Game Board's view.  It is
  45.                                                 //    passed in the constructor.  
  46.                                                 // Whenever a tile is changed the view is 
  47.                                                 //    marked needs display.
  48.                                                 // When a drawImage() is received from the
  49.                                                 //    interface object (by virtue of the view
  50.                                                 //    receiving a drawSelf:: method) the 
  51.                                                 //    tiles are composited on this view.
  52.     GameBoardView*            my_view;
  53.                                                 // This method updates the view with
  54.                                                 //    the current count.
  55.     void                    updateView( void );
  56. public:
  57.                                                 // This method comes from the interface
  58.                                                 //    object and from there the Game Board's
  59.                                                 //    view.  It is called when the view
  60.                                                 //    receives a drawSelf:: method.
  61.     void                    drawImage( void );
  62.                                                 // These methods comes from the interface
  63.                                                 //    object when the mouse is clicked
  64.                                                 //    in the Game Board's view.  
  65.                                                 // As tiles are clicked they are selected
  66.                                                 //    for removal.  A double click on a selected
  67.                                                 //    set completes the removal.
  68.     void                    click( const NXPoint* ),
  69.                             doubleClick( const NXPoint* );
  70. private:
  71.                                                 // This method is used by the click methods
  72.                                                 //    to return an index into the tile array
  73.                                                 //    to a tile that corresponds to a point
  74.                                                 //    on the Game Board.  This method returns
  75.                                                 //    -1 if no tile is found.
  76.     int                        tileForClick( const NXPoint* );
  77.                         
  78. private:
  79.                                                 // This is another object passed in the
  80.                                                 //    constructor.  It is an object that
  81.                                                 //    displays the number of tiles
  82.                                                 //    remaining on the Game Board.  
  83.     TileCountManager*        tile_count_manager;
  84.  
  85. private:    
  86.                                                 // This object is used to scramble the
  87.                                                 //    Game Board's tiles.
  88.     BoardScramble            scrambler;
  89.                                                 // This is the array of Game Tiles.  When
  90.                                                 //    a game is started this array is scrambled
  91.                                                 //    and its tiles painted on the game board.
  92.     GameTileArray            tile_array;
  93.                                                 // This member function does some house
  94.                                                 //    keeping to prepare the tiles for a new
  95.                                                 //    game.
  96.     void                    prepareTilesForPlay( void );
  97.                                                 // Scan through the tiles and make
  98.                                                 //    tiles selectable based upon surrounding
  99.                                                 //    tiles' state.
  100.     void                    updateSelectablilty( void );
  101.                                                 // While tile locations change the positions
  102.                                                 //    on the board do not.  Therefore there is
  103.                                                 //    a description for each fixed location.
  104.     TileDescriptionArray    description_array;
  105.                                                 // Tests to see if a tile is
  106.                                                 //    covered or free on its right or
  107.                                                 //    left side.
  108.     BOOL                    isFree( IntegerList& );
  109.     BOOL isCovered( int tile ) {
  110.     
  111.         
  112.         return !isFree( description_array[ tile ]->coveredList());
  113.     }
  114.     BOOL isRightFree( int tile ) {
  115.     
  116.         
  117.         return isFree( description_array[ tile ]->rightList());
  118.     }
  119.  
  120.     BOOL isLeftFree( int tile ) {
  121.     
  122.         
  123.         return isFree( description_array[ tile ]->leftList());
  124.     }
  125.  
  126.     
  127. private:
  128.                                                 // When the help button is clicked this
  129.                                                 //    object performs the help magic.
  130.     Help                    help;
  131. public:
  132.                                                 // This method is called by the interface
  133.                                                 //    object when the help button is clicked.
  134.                                                 //    See the documentation on the Help 
  135.                                                 //    object for more detail.
  136.     void                    helpClick( void );
  137.  
  138. private:
  139.                                                 // As objects are removed from the board
  140.                                                 //    they are placed on this list (in pairs)
  141.                                                 //    such that the undo button will unremove
  142.                                                 //    them.
  143.     IntegerList                    undoList;
  144.                                                 // This method removes a tile from the Game
  145.                                                 //    Board, places them on the undo list,
  146.                                                 //    and updates the attributes of its
  147.                                                 //    surrounding tiules.
  148.     void                    removeTile( int );
  149. public:
  150.                                                 // This method is called by the interface
  151.                                                 //    object when the undo button is clicked.
  152.                                                 //    This method will removed the a tile set
  153.                                                 //    from the undo list and unremove them.
  154.                                                 // The information stored is stored by an
  155.                                                 //    integer pair of indexes into the tile
  156.                                                 //    array.
  157.     void                    undoClick( void );
  158.  
  159. private:
  160.                                                 // These two variables hold the first and
  161.                                                 //    second tiles selected for removal.
  162.                                                 // A value of -1 indicates the tile isn't
  163.                                                 //    selected.
  164.     int                        first_selected_tile, second_selected_tile;
  165.                                                 // This method marks all tiles as 
  166.                                                 //    unselected.
  167.     void                    unselectTiles( void );
  168.                                                 // This method returns a tile number
  169.                                                 //    of a tile at the passed point on the
  170.                                                 //    game board.  The returned value is a
  171.                                                 //    index into tile_array.  This function
  172.                                                 //    will return -1 if no tile is found
  173.                                                 //    at the point.
  174.     int                        findTileForPoint( NXPoint* );
  175.  
  176. public:
  177.                                                 // These methods are called by the interface
  178.                                                 //    object when the Again and New buttons
  179.                                                 //    are clicked respectivly. 
  180.                                                 // Those buttons start either the previous 
  181.                                                 //    game again or a new game.
  182.     void                    againClick( void ),
  183.                             newClick( void );
  184. public:
  185.     GameCoordinator( GameBoardView*, TileCountManager* );
  186.  
  187. };
  188.  
  189.